#version 300 es

#ifdef GL_ES
precision mediump float;
#endif

#define PI 3.1415926
#define TWO_PI 6.28318530718

uniform vec2 u_resolution;
uniform float u_time;
float minStep = 0.01;

out vec4 outColor;

void main() {

  float solution = min(u_resolution.x, u_resolution.y);
  minStep = 1.0 / solution;
  vec2 st = (gl_FragCoord.xy - u_resolution / 2.0) * minStep;
  vec2 s = vec2(1.0, 1.0) - step(0.5, abs(st));
  if(s.x * s.y < 0.00001) {
    discard;
  }

  vec3 color = vec3(0.0);
  float d = 0.0;

  // Number of sides of your shape
  float N = 3.0;

  // Angle and radius from the current pixel
  float a = mod(atan(st.y, st.x) + TWO_PI, TWO_PI);
  float r = TWO_PI / N;
  // color = vec3(a / TWO_PI);

  // Shaping function that modulate the distance
  d = cos(floor(0.5 + a / r) * r - a) * length(st);
  // d = cos(floor(a / r) * r - a) * length(st);

  // d = (floor(a / r + 0.5) * r) / TWO_PI;
  // d = cos(-a);
  // d = cos(floor(a / r + 0.5) * r - a);

  color = vec3(step(0.2, d));
  color = vec3(1.0 - smoothstep(0.2, 0.21, d));
  // color = vec3(d);

  outColor = vec4(color, 1.0);
}
